<!DOCTYPE HTML>
<html>
<head>
    <title>测试</title>
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script >

        var requestCount = 0;
        var requestCount2 = 0;
        //请求的回调
        function requestCallBack(tag,response){
            //if(tag=="我是tag"){
                requestCount++;
                document.getElementById('count').innerHTML+=requestCount;
                document.getElementById("helloweb").innerHTML+=tag+" | "+response+"</br>";
                if(requestCount>=6){
                    requestCount = 0;
                    stopCount();
                }

            //}
        }
         //请求
        function request(tag,method,url,json){
            mJsCallObject.request(tag,method,url,json);
        }

        //请求
        function request(tag,json){
            mJsCallObject.request(tag,json);
        }

        window.onload = function(){//等待dom加载完毕
            <!--alert('2222');-->
            var tag = document.getElementsByTagName("h2")[0];
            //tag.innerHTML= "点我调用android原生方法";
            tag.addEventListener('click', function(){
                document.getElementById("helloweb").innerHTML="";
                document.getElementById('count').innerHTML="";
                timedCount();
                requestCount = 0;
                //调用android本地方法
                //request("我是tag","{'test1':'test1value','test2':'text2value'}");
                //request("我是tag","{'test1':'test1value','test2':'text2value'}");
                //request("我是tag","{'test1':'test1value','test2':'text2value'}");
                //request("我是tag","{'test1':'test1value','test2':'text2value'}");
                //request("我是tag","{'test1':'test1value','test2':'text2value'}");
                //request("我是tag","{'test1':'test1value','test2':'text2value'}");
                request("tag","post","https://m-uat.zhongan.com/open/cmsbanner/CmsBannerScreen/banner.json?bannerCode=mobile_home_banner","");
                return false;
            }, false);
            var random = 1;
            var tag2 = document.getElementsByTagName("h2")[1];
            tag2.addEventListener('click', function(){
                document.getElementById("helloweb2").innerHTML="";
                document.getElementById('count2').innerHTML="";
                timedCount2();
                requestCount2 = 0;
                //调用ajax方法

                $.ajax({
                    type: "GET",
                    url: "http://hbounty.com/test.php?random="+(random++),
                    success: function(data){
                        requestCount2++;
                         document.getElementById('count2').innerHTML+=requestCount2;
                         // 成功后执行的代码
                         var text = data+"<br/><br/>";
                         document.getElementById("helloweb2").innerHTML += text;  //服务器返回数据为xmlhttp.responseText
                         if(requestCount2>=6){
                            stopCount2();
                            requestCount2 = 0;
                         }
                    }
                });
                $.ajax({
                    type: "GET",
                    url: "http://hbounty.com/test.php?random="+(random++),
                    success: function(data){
                        requestCount2++;
                         document.getElementById('count2').innerHTML+=requestCount2;
                         // 成功后执行的代码
                         var text = data+"<br/><br/>";
                         document.getElementById("helloweb2").innerHTML += text;  //服务器返回数据为xmlhttp.responseText
                         if(requestCount2>=6){
                            stopCount2();
                            requestCount2 = 0;
                         }
                    }
                });
                $.ajax({
                    type: "GET",
                    url: "http://hbounty.com/test.php?random="+(random++),
                    success: function(data){
                        requestCount2++;
                         document.getElementById('count2').innerHTML+=requestCount2;
                         // 成功后执行的代码
                         var text = data+"<br/><br/>";
                         document.getElementById("helloweb2").innerHTML += text;  //服务器返回数据为xmlhttp.responseText
                         if(requestCount2>=6){
                            stopCount2();
                            requestCount2 = 0;
                         }
                    }
                });
                $.ajax({
                    type: "GET",
                    url: "http://hbounty.com/test.php?random="+(random++),
                    success: function(data){
                        requestCount2++;
                         document.getElementById('count2').innerHTML+=requestCount2;
                         // 成功后执行的代码
                         var text = data+"<br/><br/>";
                         document.getElementById("helloweb2").innerHTML += text;  //服务器返回数据为xmlhttp.responseText
                         if(requestCount2>=6){
                            stopCount2();
                            requestCount2 = 0;
                         }
                    }
                });
                $.ajax({
                    type: "GET",
                    url: "http://hbounty.com/test.php?random="+(random++),
                    success: function(data){
                        requestCount2++;
                         document.getElementById('count2').innerHTML+=requestCount2;
                         // 成功后执行的代码
                         var text = data+"<br/><br/>";
                         document.getElementById("helloweb2").innerHTML += text;  //服务器返回数据为xmlhttp.responseText
                         if(requestCount2>=6){
                            stopCount2();
                            requestCount2 = 0;
                         }
                    }
                });
                $.ajax({
                    type: "GET",
                    url: "http://hbounty.com/test.php?random="+(random++),
                    success: function(data){
                        requestCount2++;
                         document.getElementById('count2').innerHTML+=requestCount2;
                         // 成功后执行的代码
                         var text = data+"<br/><br/>";
                         document.getElementById("helloweb2").innerHTML += text;  //服务器返回数据为xmlhttp.responseText
                         if(requestCount2>=6){
                            stopCount2();
                            requestCount2 = 0;
                         }
                    }
                });


                //createxmlHttp();
                //createRequest();
                //createRequest();
                //createRequest();

                return false;
            }, false);
        }

        //下面是个计时器
        var c=0;//毫秒
        var t;
        function timedCount(){
         document.getElementById('time').innerHTML=c+" 毫秒"
         c=c+1
         t=setTimeout("timedCount()",1)
        }
        //停止计时
        function stopCount(){
         clearTimeout(t)
         c = 0;
        }


        //---------------------------下面是ajax请求---------------------------------------------
       var xmlhttp;
        function createxmlHttp(){

          //创建xmlhttp对象
          if (window.XMLHttpRequest)
              xmlhttp=new XMLHttpRequest();
          else
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
         }
    function callbacksuccess()
     {
       if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
            requestCount2++;
             document.getElementById('count2').innerHTML+=requestCount2;
             // 成功后执行的代码
             var text = xmlhttp.responseText+"<br/><br/>";
             document.getElementById("helloweb2").innerHTML += text;  //服务器返回数据为xmlhttp.responseText
             if(requestCount2>=3){
                stopCount2();
                requestCount2 = 0;
             }
          }else{
          //stopCount2();
          //alert(xmlhttp.responseText);
          //alert(xmlhttp.readyState);
          //alert(xmlhttp.status);
          }
     }

    var random = 1;
     function createRequest(){
        createxmlHttp();
        random++;
        var url = "http://hbounty.com/test.php?time="+random;
        xmlhttp.open('GET',url,true);     //发送ajax
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.onreadystatechange=callbacksuccess;    //回调函数
        xmlhttp.send();  //get时data为null
     }



     //下面是个计时器
        var c2=0;//毫秒
        var t2;
        function timedCount2(){
         document.getElementById('time2').innerHTML=c2+" 毫秒"
         c2=c2+1
         t2=setTimeout("timedCount2()",1)
        }
        //停止计时
        function stopCount2(){
         clearTimeout(t2)
         c2 = 0;
        }

    </script>

</head>

<body>
    <h1>jsbridge</h1>
    <h2>点击我调用android原生的请求</h2>

    <!--<a href="http://www.baidu.com">百度</a>-->
    <div id="time" style="height:20px;background:#F2F2F2;color:red;padding:10px;">
    </div>
    <div id="count" style="height:20px;background:#F2F2F2;color:red;padding:10px;">
    </div>
    <div id="helloweb" style="height:200px;background:#CCCCCC;padding:10px;">
    </div>

    <h2>点击我调用ajax的请求</h2>
    <div id="time2" style="height:20px;background:#F2F2F2;color:red;padding:10px;">
    </div>
    <div id="count2" style="height:20px;background:#F2F2F2;color:red;padding:10px;">
    </div>
    <div id="helloweb2" style="height:200px;background:#CCCCCC;padding:10px;">
    </div>


</body>
</html>